
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>商品管理</title>
    {include file='header'}
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a>广告管理</a>
            <a><cite>列表</cite></a>
        </span>
        <div style="float: right;">            
            <a href="javascript:;" onclick="xadmin.open('添加','{:url('modify')}')"><button class="layui-btn"><i class="layui-icon">&#xe61f;</i>添加</button></a>
            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="x-body">
               <table class="layui-table">
            <thead>
                <tr>
                    <th style="width: 25px;">
                        <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
                    </th>
                    <th style="width:120px;">位置</th>
                    <th>标题</th>                    
                    <th style="width:80px;text-align: center;">图片</th>
                    <th>内容</th>
                    <th>链接</th>
                    <th style="width: 70px; text-align: center;">状态</th>
                    <th style="width: 120px;text-align: center;">操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach $data_list as $vo}
                <tr>
                    <td style="width: 25px;">
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
                    </td>
                    <td>{$vo.category_name}</td>
                    <td>{$vo.title}</td>
                    <td style="width:80px;text-align: center;">{if !empty($vo.images)}<a href="{$vo.images}" target="_blank"><img src="{$vo.images}" height=60 /></a>{/if}</td>
                    <td>{$vo.contents}</td>
                    <td>{$vo.url}</td>
                    <td>{if $vo.status==0}无效{else}有效{/if}</td>
                    <td class="td-manage">
                        <a class="layui-btn layui-btn-xs" href="{:url('modify',['id'=>$vo.id])}">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove('{$vo.id}')">删 除</a>
                    </td>
                </tr>{/foreach}             
            </tbody>
        </table>
        {$page|raw}
    </div>
    <script>
    function set_status(id,status){
        $.post("{:url('status')}",{id:id,status:status},function(res){
        if(res.code==0)
        {
          layer.msg('操作成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      },'json');
    }
    function remove(id)
    {
        if(confirm('确定要删除数据吗?'))
        {
        $.post("{:url('remove')}",{id:id},function(res){
            if(res.code==0)
            {
            layer.msg('删除成功',{icon:1,time:1000},function(){
                location.reload();
            })
            }
            else
            {
            layer.msg('操作失败');
            }
        })
        }
    }
    /*用户-批量删除*/
    function delAll(argument) {
        var ids = tableCheck.getData().toString();
        if (ids == "") {
            layer.msg('请选择要删除的数据！', { icon: 0 });
            return false;
        }
        layer.confirm('确认要删除所选吗？', function (index) {
            layer.close(index);
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: "POST",
                url: "{:url('remove')}",
                data: { "id": ids },
                datatype: "json",
                success: function (res, textStatus) {                   
                    if (res.state == 0) {
                        layer.msg(res.msg, { icon: 1, time: 2000 });
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                    else {
                        layer.alert(res.msg, { icon: 5 });
                        return false;
                    }
                },
                error: function (e) {
                    layer.alert('系统出现错误,请检查系统！', { icon: 2 });//0感叹号  1打勾  2打叉  3问号  4锁头  5难过  6笑脸
                    return false;
                }
            });
        });
    }
    </script>
</body>
</html>